﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Microsoft.Popfly.GameCreator.GameEngine
{
    public partial class PauseScreen : Canvas
    {
        private Game m_game;
        
        private void SetPlayPositionAndScale()
        {
            double scale = Math.Min(Height / playButton.Height, Width / playButton.Width);
            
            ScaleTransform scaleTransform = new ScaleTransform();
            scaleTransform.ScaleX = scale;
            scaleTransform.ScaleY = scale;
            playButton.RenderTransform = scaleTransform;

            if (Height > Width)
            {
                Canvas.SetTop(playButton, (Height - playButton.Height * scale) / 2);
            }
            else
            {
                Canvas.SetLeft(playButton, (Width - playButton.Width * scale) / 2);
            }
        }


        public PauseScreen(Game game, double width, double height)
        {
            InitializeComponent();

            Width = width;

            Height = height;

            m_game = game;

            MouseEnter += new MouseEventHandler(PauseScreen_MouseEnter);
            MouseLeave += new MouseEventHandler(PauseScreen_MouseLeave);

            SetPlayPositionAndScale();
        }

        void PauseScreen_MouseLeave(object sender, MouseEventArgs e)
        {
            unglow.Begin();
        }

        void PauseScreen_MouseEnter(object sender, MouseEventArgs e)
        {
            glow.Begin();
        }

        private void Canvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            m_game.UnPause();
        }
    }
}
